<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );
class Company_user extends CI_Controller {
	public function __construct() {
		parent::__construct ();
		$this->load->model ( 'function_model' );
		$this->load->model ( 'MChain' );
		//$this->output->enable_profiler(true);
		if(($this->session->userdata('logged_user')==false))
		{
			echo "<script>alert('Please Login again');</script>";
			redirect("login_user/user_login", "refresh");
		}
	}
	
	
	public function index() {
		$data ['title'] = 'Company Infomation';
		$data ['groups'] = $this->function_model->getCompanyInfo ($this->session->userdata('user_company'));
		$data ['branch'] = $this->function_model->getBranchCompany ($this->session->userdata('user_company'));
		$this->load->view ( 'header', $data );
		$this->load->view ( "company_info", $data );
	}
	
	
	public function edit_company() {
		$this->load->library ( 'form_validation' );
		// field name, error message, validation rules
		$this->form_validation->set_rules ( 'email', 'Your Email', 'trim|required|valid_email|min_length[5]|max_length[100]' );
		$this->form_validation->set_rules ( 'tel_number1', 'Telephone Number', 'trim|required|is_numeric|min_length[1]|max_length[4]' );
		$this->form_validation->set_rules ( 'tel_number2', 'Telephone Number', 'trim|required|is_numeric|min_length[1]|max_length[4]' );
		$this->form_validation->set_rules ( 'tel_number3', 'Telephone Number', 'trim|required|is_numeric|min_length[1]|max_length[4]' );
		$this->form_validation->set_rules ( 'address', 'Address', 'trim|required|xss_clean' );
		$this->form_validation->set_rules ( 'fax1', 'Fax Number', 'trim|required|is_numeric|min_length[1]|max_length[4]' );
		$this->form_validation->set_rules ( 'fax2', 'Fax Number', 'trim|required|is_numeric|min_length[1]|max_length[4]' );
		$this->form_validation->set_rules ( 'fax3', 'Fax Number', 'trim|required|is_numeric|min_length[1]|max_length[4]' );
		$this->form_validation->set_rules ( 'con_tel1', 'Contact Telephone', 'trim|required|is_numeric|min_length[1]|max_length[4]' );
		$this->form_validation->set_rules ( 'con_tel2', 'Contact Telephone', 'trim|required|is_numeric|min_length[1]|max_length[4]' );
		$this->form_validation->set_rules ( 'con_tel3', 'Contact Telephone', 'trim|required|is_numeric|min_length[1]|max_length[4]' );
		$this->form_validation->set_rules ( 'con_name', 'Contact Name', 'trim|required|xss_clean|min_length[2]|max_length[100]' );
	
		if ($this->form_validation->run () == FALSE) {
			$this->index ();
		} else {
			$this->function_model->edit_company_user ();
			// $id = $this->db->insert_id();
			// $member = $this->function_model->get_member_by_id($id);
			// $this->send_email("activate", $member);
			$this->thank ();
		}
	}
	
	
	public function thank() {
		$data ['title'] = 'Thank';
		$this->load->view ( 'header', $data );
		$this->load->view ( 'end_user_register_suscess', $data );
		$this->load->view('footer',$data);
	}
	
}
?>